package com.han.bom.tests;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.han.bom.Exam;
import com.han.bom.MultipleChoice;
import com.han.bom.Question;
import com.han.bom.RealExam;
import com.han.bom.TrueOrFalse;

public class ExamTest {

	private Exam exam = null;
	
	@Before
	public void setUp() throws Exception {
		
		ArrayList<Question> questions = new ArrayList<Question>();
		
		exam = new RealExam();
		
		for(int i=0;i<10;i++){
			questions.add(new MultipleChoice());
			questions.add(new TrueOrFalse());
		}
		
		exam.setQuestions(questions);
		
	}

	@After
	public void tearDown() throws Exception {
		
		exam=null;
		
	}

	@Test
	public void testSearchQuestion() {
		
		ArrayList<String> randomStrings = new ArrayList<String>();
		randomStrings.add("");
		randomStrings.add(null);
		randomStrings.add("not an ID");
		randomStrings.add("examid");
		randomStrings.add("nope");
		
		for(int i=0;i<30;i++){
			
			if(i<20){
				Question question = exam.getQuestions().get(i);
				
				assertEquals(question,exam.searchQuestion(question.getQuestionID()));
				
			}
			else{
				for(Question question: exam.getQuestions()){
					for(String s:randomStrings){
						assertNotSame(question, exam.searchQuestion(s));
					}
				}
				
				
			}
			
		}
		
	}

}
